package com.zhudeshuai.zhudemolist.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.zhu.zhuCore.utils.LogUtil;
import com.zhudeshuai.zhudemolist.R;
import com.zhudeshuai.zhudemolist.adapter.ImageAdapter;
import com.zhudeshuai.zhudemolist.base.BaseActivity;
import com.zhudeshuai.zhudemolist.widget.MyScrollView.MyScrollListener;
import com.zhudeshuai.zhudemolist.widget.MyScrollView.MyScrollView;

/**
 * 特定view
 *
 * @author zhudeshuai
 * @since 17/12/6
 */
public class MyScrollViewActivity extends BaseActivity {



	private MyScrollView mMyScrollView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_scroll_view);
		mMyScrollView = (MyScrollView) findViewById(R.id.my_scrollview);
		mMyScrollView.setAdapter(new ImageAdapter(this));

		/*TextView textView = new TextView(this);
		textView.setText(R.string.large_content);
		mMyScrollView.addView(textView)*/;
		addWebView();
		addHeaderText();

		mMyScrollView.setScrollListener(new MyScrollListener() {
			@Override
			public void onHeaderScrollToMax() {
				LogUtil.d("zhu1", "onHeaderScrollToMax");
			}

			@Override
			public void onHeaderScrollToMin() {
				LogUtil.d("zhu1", "onHeaderScrollToMin");
			}
		});

	}

	private void addHeaderText() {
		TextView headerTextView = new TextView(this);
		headerTextView.setPadding(20,20,20,20);
		headerTextView.setBackgroundColor(Color.parseColor("#ed6f43"));
		headerTextView.setText("售卖时间较长，将于3天后下架，建议使用推广产品");
		headerTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
		mMyScrollView.addView(headerTextView,0);
	}

	private void addWebView() {
		WebView webView = new WebView(this);
		webView.setWebViewClient(new WebViewClient(){
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return super.shouldOverrideUrlLoading(view, url);
			}
		});
		webView.loadUrl("http://m.che168.com");
		mMyScrollView.addView(webView);
	}

	public static void open(Activity activity) {
		open(activity, MyScrollViewActivity.class);
	}

	/*public void toReduce(View view) {
		final ViewGroup.LayoutParams layoutParams = mRecyclerView.getLayoutParams();
		ValueAnimator valueAnimator = ValueAnimator.ofInt(mRecyclerView.getHeight(),mRecyclerView.getHeight() - 50);
		valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				int value = (int) animation.getAnimatedValue();
				layoutParams.height = value;
				mRecyclerView.setLayoutParams(layoutParams);
				mRecyclerView.getAdapter().notifyDataSetChanged();
			}
		});
		valueAnimator.start();
	}

	public void toAdd(View view) {
		final ViewGroup.LayoutParams layoutParams = mRecyclerView.getLayoutParams();
		ValueAnimator valueAnimator = ValueAnimator.ofInt(mRecyclerView.getHeight(),mRecyclerView.getHeight() + 50);
		valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				int value = (int) animation.getAnimatedValue();
				layoutParams.height = value;
				mRecyclerView.setLayoutParams(layoutParams);
				mRecyclerView.getAdapter().notifyDataSetChanged();
			}
		});
		valueAnimator.start();


	}*/
}
